<?php

/**
 * This is the model class for table "xman_bug".
 *
 * The followings are the available columns in table 'xman_bug':
 * @property integer $bug_id
 * @property string $bug_name
 * @property string $bug_description
 * @property integer $bug_list_id
 * @property string $bug_impact
 * @property integer $bug_priority
 * @property string $bug_happened_date
 * @property string $bug_updated_date
 * @property string $bug_completed_date
 * @property integer $bug_posted_by_user_id
 *
 * The followings are the available model relations:
 * @property User $bugPostedByUser
 * @property BugList $bugList
 */
class Bug extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Bug the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_bug';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('bug_name, bug_list_id, bug_posted_by_user_id', 'required'),
			array('bug_list_id, bug_priority, bug_posted_by_user_id', 'numerical', 'integerOnly'=>true),
			array('bug_name, bug_impact', 'length', 'max'=>50),
			array('bug_description', 'length', 'max'=>100),
			array('bug_happened_date, bug_updated_date, bug_completed_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('bug_id, bug_name, bug_description, bug_list_id, bug_impact, bug_priority, bug_happened_date, bug_updated_date, bug_completed_date, bug_posted_by_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bugPostedByUser' => array(self::BELONGS_TO, 'User', 'bug_posted_by_user_id'),
			'bugList' => array(self::BELONGS_TO, 'BugList', 'bug_list_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'bug_id' => 'Bug',
			'bug_name' => 'Bug Name',
			'bug_description' => 'Bug Description',
			'bug_list_id' => 'Bug List',
			'bug_impact' => 'Bug Impact',
			'bug_priority' => 'Bug Priority',
			'bug_happened_date' => 'Bug Happened Date',
			'bug_updated_date' => 'Bug Updated Date',
			'bug_completed_date' => 'Bug Completed Date',
			'bug_posted_by_user_id' => 'Bug Posted By User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('bug_id',$this->bug_id);
		$criteria->compare('bug_name',$this->bug_name,true);
		$criteria->compare('bug_description',$this->bug_description,true);
		$criteria->compare('bug_list_id',$this->bug_list_id);
		$criteria->compare('bug_impact',$this->bug_impact,true);
		$criteria->compare('bug_priority',$this->bug_priority);
		$criteria->compare('bug_happened_date',$this->bug_happened_date,true);
		$criteria->compare('bug_updated_date',$this->bug_updated_date,true);
		$criteria->compare('bug_completed_date',$this->bug_completed_date,true);
		$criteria->compare('bug_posted_by_user_id',$this->bug_posted_by_user_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	/**
	 * return all bug priority
	 */
	 public function listPriority(){
	 	return array(
		 	'1'=>'High',
		 	'2'=>'Medium',
		 	'3'=>'Low',
	 	);
	 }
}